<template>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>
            <a href="/">出入库管理</a>
        </el-breadcrumb-item>
        <el-breadcrumb-item>库存盘点</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 查询 -->
    <div style="margin: 30px 3px;padding: 30px;">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="类型编码">
                <el-input v-model="formInline.Warehouseid" placeholder="请输入类型编码" clearable />
            </el-form-item>

            <el-form-item label="类型名称">
                <el-input v-model="formInline.Status" placeholder="请输入类型名称" clearable />
            </el-form-item>

            <el-form-item label="类型编码">
                <el-input v-model="formInline.Depid" placeholder="请输入类型编码" clearable />
            </el-form-item>

            <el-form-item label="类型名称">
                <el-input v-model="formInline.Empid" placeholder="请输入类型名称" clearable />
            </el-form-item>

            <el-form-item>
                <el-button type="success" @click="GetGoodsTypeTreeAsync">查询</el-button>
                <el-button type="danger" @click="Reset">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
    <!-- 显示 -->
    <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="warehouseid" label="仓库编码" width="180" />
        <el-table-column prop="warehousename" label="仓库名称" width="140" />
        <el-table-column prop="capacity" label="仓库容量" width="80" />
        <el-table-column prop="address" label="地址" width="80" />
        <el-table-column prop="depid" label="部门ID" width="80" />
        <el-table-column prop="empid" label="仓库主管" width="80" />
        <el-table-column prop="librarylocationnum" label="库位数量" width="80" />

        <el-table-column prop="status" label="状态" width="80">
            <template v-slot="setup">
                <el-tag v-if="setup.row.status == '开启'" type="success">开启</el-tag>
                <el-tag v-else type="danger">禁用</el-tag>
            </template>
        </el-table-column>

        <el-table-column label="操作">
            <template v-slot="setup">
                <!-- <el-button type="primary" @click="UpdateGoodsType" size="small">编辑</el-button> -->
                <el-button type="danger" @click="DelGoodsType(setup.row.id)" size="small">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, onMounted, reactive } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus'
import { watch } from 'vue'
import type { TreeInstance } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'

//分页参数
const PageInfo = ref({
    pageIndex: 1,
    pageSize: 5,
    totalCount: 0,
    totalPages: 0
})

//查询参数
const formInline = ref({
    Warehouseid: "",
    Status: "",
    Depid: "",
    Empid: ""
})

const tableData = ref([{
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "creationTime": "2025-07-24T06:51:41.966Z",
    "creatorId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "lastModificationTime": "2025-07-24T06:51:41.966Z",
    "lastModifierId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "warehouseid": "string",
    "warehousename": "string",
    "capacity": "string",
    "address": "string",
    "depid": 0,
    "empid": 0,
    "librarylocationnum": "string",
    "status": "string"
}])

//钩子函数
onMounted(() => {
    GetGoodsTypeTreeAsync();
})

//获取盘点信息
const GetGoodsTypeTreeAsync = () => {
    axios.get("http://localhost:8080/api/app/warehouse/warehouses-list",
        {
            params: {
                Warehouseid: formInline.value.Warehouseid,
                Status: formInline.value.Status,
                Depid: formInline.value.Depid,
                Empid: formInline.value.Empid,

                SkipCount: PageInfo.value.pageIndex,
                MaxResultCount: PageInfo.value.pageSize
            }
        }
    )
        .then(res => {
            tableData.value = res.data.items;
            PageInfo.value.totalCount = res.data.totalCount;
            PageInfo.value.totalPages = Math.ceil(PageInfo.value.totalPages * 1.0 / PageInfo.value.pageSize);
        })
}

//重置按钮
const Reset = () => {
    formInline.value.Warehouseid = "";
    formInline.value.Status = "";
    formInline.value.Depid = "";
    formInline.value.Empid = "";
}

//删除按钮
const DelGoodsType = (id: string) => {
    ElMessageBox.confirm(
        '确定删除?',
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
}
</script>

<style>
.demo-form-inline .el-input {
    --el-input-width: 220px;
}

.demo-form-inline .el-select {
    --el-select-width: 220px;
}
</style>